//
// Created by 刘进伟 on 2018/5/22.
//

#include "TokeErgo.h"

TokeErgo::TokeErgo(std::list<Token> &tokenList) : tokenBuffer(tokenList)
{
    curToken = tokenBuffer.begin();
}

void TokeErgo::goAhead()
{
    if (curToken == tokenBuffer.end());
    else
        ++curToken;
}

bool TokeErgo::isEmpty()
{
    if (curToken == tokenBuffer.end())
        return true;
    else
        return false;
}

Token &TokeErgo::getCurrentToken()
{
    return *curToken;
}

void TokeErgo::printTree(LexType lex, int level)
{
    std::string translation[] = { std::string(" "),std::string("PROGRAM"), std::string("PROCEDURE"), std::string("TYPE"),
                                  std::string("VAR"), std::string("IF"), std::string("THEN"), std::string("ELSE"),
                                  std::string("FI"),
                                  std::string("WHILE"), std::string("DO"), std::string("ENDWH"), std::string("BEGIN"),
                                  std::string("END"),
                                  std::string("READ"), std::string("WRITE"), std::string("ARRAY"), std::string("OF"),
                                  std::string("RECORD"),
                                  std::string("RETURN"), std::string("INTEGER"), std::string("CHAR"), std::string("ID"),
                                  std::string("INTC"), std::string("CHARC"), std::string("ASSIGN"),
                                  std::string("EQ"),
                                  std::string("LT"),
                                  std::string("PLUS"),
                                  std::string("MINUS"),
                                  std::string("TIMES"),
                                  std::string("OVER"),
                                  std::string("LPAREN"),
                                  std::string("RPAREN"),
                                  std::string("DOT"),
                                  std::string("COLON"),
                                  std::string("SEMI"),
                                  std::string("COMMA"),
                                  std::string("LMIDPAREN"),
                                  std::string("RMIDPAREN"),
                                  std::string("UNDERANGE"),
                                  std::string("ERROR"),
                                  std::string("ENDOFILE"),
                                  std::string("Program"),
                                  std::string("ProgramHead"),
                                  std::string("ProgramName"),
                                  std::string("DeclarePart"),
                                  std::string("ProcDecpart"),
                                  std::string("TypeDec"),
                                  std::string("TypeDecList"),
                                  std::string("TypeDecMore"),
                                  std::string("TypeDecpart"),
                                  std::string("TypeId"),
                                  std::string("BaseType"),
                                  std::string("StructureType"),
                                  std::string("ArrayType"),
                                  std::string("Low"), std::string("Top"),
                                  std::string("RecType"), std::string("FieldDecList"), std::string("FieldDecMore"),
                                  std::string("IdList"),
                                  std::string("IdMore"), std::string("VarDec"), std::string("VarDecList"),
                                  std::string("VarDecMore"),
                                  std::string("VarDecpart"), std::string("VarIdList"), std::string("VarIdMore"),
                                  std::string("ProcDec"),
                                  std::string("ProcDeclaration"), std::string("ProcDecMore"), std::string("ProcName"),
                                  std::string("ParamList"),
                                  std::string("ParamDecList"), std::string("ParamMore"), std::string("Param"),
                                  std::string("FormList"),
                                  std::string("FidMore"), std::string("ProcDecPart"), std::string("ProcBody"),
                                  std::string("ProgramBody"),
                                  std::string("StmList"), std::string("StmMore"), std::string("Stm"),
                                  std::string("AssCall"),
                                  std::string("AssignmentRest"), std::string("ConditionalStm"), std::string("LoopStm"),
                                  std::string("InputStm"),
                                  std::string("Invar"), std::string("OutputStm"), std::string("ReturnStm"),
                                  std::string("CallStmRest"),
                                  std::string("ActParamList"), std::string("ActParamMore"), std::string("RelExp"),
                                  std::string("OtherRelE"),
                                  std::string("Exp"), std::string("OtherTerm"), std::string("Term"),
                                  std::string("OtherFactor"),
                                  std::string("Variable"), std::string("VariMore"), std::string("FieldVar"),
                                  std::string("FieldVarMore"),
                                  std::string("CmpOp"), std::string("AddOp"), std::string("MultOp"),
                                  std::string("TypeDef") };


    for (int i = 0; i < level; ++i)
        std::cout << "  ";
    std::cout << "类型：" << lex << " " << translation[lex] << std::endl;
}
